package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.yadiudiu.model.WaitingModel;
import com.diudiutechnology.www.yadiudiu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/9/1.
 */

public class OrderDetailsAdapter extends BaseAdapter {

    private Context mContext;
    List<WaitingModel> model= new ArrayList<>();
    String merchanttype="";
    public OrderDetailsAdapter(Context context,String merchanttype) {
        this.mContext = context;
        this.merchanttype=merchanttype;
    }

    @Override
    public int getCount() {
        return model.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    public void addItem( List<WaitingModel> model){

        this.model=model;
        notifyDataSetChanged();
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_order_details, null);
            holder.item_title= (TextView) convertView.findViewById(R.id.item_title);
            holder.item_number= (TextView) convertView.findViewById(R.id.item_number);
            holder.amount= (TextView) convertView.findViewById(R.id.amount);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (merchanttype.equals("3")||merchanttype.equals("5")){
            holder.item_title.setText(model.get(position).getProductname());
            holder.item_number.setText("×"+model.get(position).getQuantity());
            holder.amount.setText("¥"+model.get(position).getUnitprice());
        } else if (merchanttype.equals("8")) {//家政商家
            holder.item_title.setText(model.get(position).getProductname());
            holder.item_number.setText(model.get(position).getQuantity());
            holder.amount.setText(model.get(position).getUnitprice());
        }else {
            holder.item_title.setText(model.get(position).getProductname());
            holder.item_number.setText(model.get(position).getQuantity());
            holder.amount.setText("¥"+model.get(position).getUnitprice());
        }

        return convertView;
    }

    class ViewHolder {
        TextView item_title;
        TextView item_number;
        TextView amount;

    }
}

